package com.atguigu.TCP_a;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/*1.创建Socket对象,指明服务端的ip以及端口号
2.调用socket中的getOutputStream,往服务端发送请求
3.调用socket中的getInputStream,读取服务端响应回来的数据
4.关流*/

public class Client {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("127.0.0.1", 6666);//创建Socket对象，指明服务器的IP和端口

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("我想下载一个小电影".getBytes());

        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int length = inputStream.read(bytes);

        System.out.println(new String(bytes,0,length));

        inputStream.close();  //4.关流
        outputStream.close();
        socket.close();
    }
}
